package com.yuncheng.spcyApi.spcyService;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yuncheng.spcyApi.busService.InitWjjlService;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.constant.xcjchy.SqsxHyConstant;
import com.yuncheng.spcyApi.entity.*;
import com.yuncheng.spcyApi.flow.JcyRckpFlowService;
import com.yuncheng.spcyApi.flow.JcyRckpHpFlowService;
import com.yuncheng.spcyApi.flow.JcyYbkpFlowService;
import com.yuncheng.spcyApi.flow.SpcyFlowConstant;
import com.yuncheng.spcyApi.mapper.SpcySqsxJobMapper;
import com.yuncheng.spcyApi.mapper.SpcySqsxXpjlMapper;
import com.yuncheng.spcyApi.service.ISpcySqsxHymxService;
import com.yuncheng.spcyApi.service.ISpcySqsxHyztService;
import com.yuncheng.spcyApi.utils.GetCurrentUserUtils;
import com.yuncheng.spcyApi.utils.GetUuIdUtils;
import com.yuncheng.spcyApi.vo.spcy.SpcyXpryUserVo;
import com.yuncheng.system.permission.service.h.E;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import com.yuncheng.spcyApi.vo.common.Result;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author hua
 */
@Service
public class SqsxYwxxInfoService {

    private static final Logger log = LoggerFactory.getLogger(SqsxYwxxInfoService.class);

    @Resource
    @Lazy
    private JcyRckpFlowService jcyRckpFlowService;

    @Resource
    @Lazy
    private JcyYbkpFlowService jcyYbkpFlowService;

    @Resource
    @Lazy
    private JcyRckpHpFlowService jcyRckpHpFlowService;

    @Resource
    private JcyFybxdService jcyFybxdService;

    @Resource
    private ISpcySqsxHyztService spcySqsxHyztService;

    @Resource
    private ISpcySqsxHymxService spcySqsxHymxService;

    @Resource
    private SpcyMyInfoService spcyMyInfoService;

    @Resource
    private InitWjjlService initWjjlService;

    @Resource
    private SpcySqsxJobMapper spcySqsxJobMapper;

    @Resource
    private SpcySqsxXpjlMapper spcySqsxXpjlMapper;

    @Resource
    @Lazy
    private SpcyMyddcService spcyMyddcService;

    /**
     * 初始化-日常考评、检查员互评、见习考评流程
     * */
    @Async(value = "asyncNormalTask")
    public void initJcyRckpOrYbkpOrHp(String sqsxid, SpcySqsxBasic sqsx){

        /** 初始化-日常考评流程 */
        try {
            jcyRckpFlowService.initJob(sqsxid, GetCurrentUserUtils.getCurrentUser());
        }catch (Exception e){
            log.error("方案审批提交-初始化-日常考评流程错误：{}", e.getMessage());
        }

        /** 初始化-预备检查员 */
        try {
            jcyYbkpFlowService.joinYbJcyJob(sqsxid);
        }catch (Exception e){
            log.error("方案审批提交-初始化-预备检查员错误：{}", e.getMessage());
        }


        /** 初始化-检查员互评 */
        try {
            jcyRckpHpFlowService.initRckpHpFlow(sqsxid);
        }catch (Exception e){
            log.error("方案审批提交-初始化-检查员互评错误：{}", e.getMessage());
        }


        /** 初始现场检查会议 */
        try {
            this.initSqsxHy(sqsxid, sqsx);
        }catch (Exception e){
            log.error("方案审批提交-初始现场检查会议错误：{}", e.getMessage());
        }


        /** 初始化检查员费用报销单 */
        try {
            jcyFybxdService.initSqsxFybxd(sqsxid, sqsx);
        }catch (Exception e){
            log.error("方案审批提交-初始化检查员费用报销单-错误：", e.getMessage());
        }

        /** 方案及相关文件自动盖章 */
//        initWjjlService.verifyAutoFileGzByFazd(sqsxid);
    }

    /**
     * 数据修订-同步更新选派人员相关数据
     * @param isExistsAddYbjcy 是否存在新增预备检查员
     * @param removeYbjcyIdList 预备检查员用户id列表
     * @param addZzUserIdList 添加组长用户id
     * @param removeZzUserIdList 移除组长用户id
     * @param addUserIdList 新增用户id列表
     * @param removeUserIdList 移除用户id列表
     * */
    @Async(value = "asyncMiddleTask")
    public void syncJcyInfoDataWithSjxd(String sqsxid,
                                        SpcySjxdJbxx sjxd, SpcySqsxBasic sqsx,
                                        boolean isExistsAddYbjcy, List<String> removeYbjcyIdList,
                                        List<String> addZzUserIdList, List<String> removeZzUserIdList,
                                        List<String> addUserIdList, List<String> removeUserIdList){

        /** 初始化-检查员互评 */
        if (CollectionUtil.isNotEmpty(addUserIdList)) {
            try {
                jcyRckpHpFlowService.initRckpHpFlow(sqsxid);
            } catch (Exception e) {
                log.error("数据修订同步-初始化-检查员互评错误：{}", e.getMessage());
            }

            /** 数据修订-同步新增报销人员记录 */
            try {
                jcyFybxdService.syncBxryWithSjxd(sqsxid);
            } catch (Exception e) {
                log.error("数据修订同步-同步新增报销人员记录-错误：", e.getMessage());
            }

            if (isExistsAddYbjcy){
                /** 初始化-预备检查员 */
                try {
                    jcyYbkpFlowService.joinYbJcyJob(sqsxid);
                }catch (Exception e){
                    log.error("数据修订同步-初始化-预备检查员错误：{}", e.getMessage());
                }
            }
        }

        if (CollectionUtil.isNotEmpty(removeUserIdList)){
            for (String fuserid : removeUserIdList) {
                /** 同步移除检查员互评 */
                jcyRckpHpFlowService.syncDelRckpHpFlow(sqsxid, fuserid);

                /** 同步移除报销人员记录和会议登记人员 */
                jcyFybxdService.syncDelBxryAndDjry(sqsxid, fuserid);
            }

            /** 同步移除会议登记人员签到记录 */
            spcySqsxHyztService.deleteHymxByFSqsxidAndUserIds(sqsxid, removeUserIdList);
        }

        /** 同步移除-预备检查员流程 */
        if (CollectionUtil.isNotEmpty(removeYbjcyIdList)){
            for (String fuserid : removeYbjcyIdList) {
                jcyYbkpFlowService.syncDelYbjcyFlow(sqsxid, fuserid);
            }
        }

        /** 同步更新-预备检查员流程-组长信息 */
        if (CollectionUtil.isNotEmpty(addZzUserIdList) || CollectionUtil.isNotEmpty(removeZzUserIdList)) {
            jcyYbkpFlowService.syncUpdateZzInfo(sqsxid);
        }

        /** 同步更新-预备检查员流程-检查日期 */
        jcyYbkpFlowService.syncUpdateJcsjInfo(sqsxid, sjxd.getFxdjckssj(), sjxd.getFxdjcjssj());

        /** 更新审评流程待办-现场检查环节待办人 */
        this.syncSpcyXcjcJob(sqsxid);

        /** 满意度调查问卷同步检查员评价 */
        spcyMyddcService.syncUpdateMydJcyPj(sqsxid, sjxd.getFxdjckssj(), sjxd.getFxdjcjssj(), removeUserIdList, addUserIdList);

    }

    /** 更新审评流程-现场检查环节待办人 */
    private void syncSpcyXcjcJob(String sqsxid){
        List<SpcyXpryUserVo> tyxpList = spcySqsxXpjlMapper.selectXpUserBeanListByFsqsxId(sqsxid, SpcyConstant.XPJL_SFTYXP_YES);
        if (CollectionUtil.isEmpty(tyxpList)){
            return;
        }

        String dbrId = "";
        String dbr = "";

        for (SpcyXpryUserVo xpjl : tyxpList){
            if (StringUtils.isBlank(dbrId)){
                dbrId += xpjl.getFuserid();
                dbr += xpjl.getFjcyxm() + "(" + Optional.ofNullable(xpjl.getFssk()).orElseGet(() -> "组员") + ")";
            }else {
                dbrId += "," + xpjl.getFuserid();
                dbr += "," + xpjl.getFjcyxm() + "(" + Optional.ofNullable(xpjl.getFssk()).orElseGet(() -> "组员") + ")";
            }
        }

        LambdaUpdateWrapper<SpcySqsxJob> updateJobWq = new LambdaUpdateWrapper<>();
        updateJobWq.eq(SpcySqsxJob::getFpid, sqsxid);
        updateJobWq.eq(SpcySqsxJob::getFhjmc, SpcyFlowConstant.HJMC_XCJC);
        updateJobWq.ne(SpcySqsxJob::getFnodeid, SpcyFlowConstant.ZDY_HJMC_BQBZ_NODE_ID);

        SpcySqsxJob updateJob = new SpcySqsxJob();
        updateJob.setFdbrid(dbrId);
        updateJob.setFdbr(dbr);

        updateJob.setFydbrid(dbrId);
        updateJob.setFydbr(dbr);
        spcySqsxJobMapper.update(updateJob, updateJobWq);
    }

    /**
     * 初始化检查员费用报销单
     * */
    public void initSqsxJcyBxd(String sqsxid, SpcySqsxBasic sqsx){
        jcyFybxdService.initSqsxFybxd(sqsxid, sqsx);
    }

    /**
     * 初始化申请事项-首次会议-末次会议
     * */
//    @Async(value = "asyncNormalTask")
    public void initSqsxHy(String sqsxid, SpcySqsxBasic sqsx){

        List<SpcySqsxHyzt> list = spcySqsxHyztService.list(new LambdaQueryWrapper<SpcySqsxHyzt>().eq(SpcySqsxHyzt::getFsqsxid, sqsxid));
        if (CollectionUtil.isNotEmpty(list)){
            return;
        }

        List<SpcySqsxHyzt> hyList = new ArrayList<>();
        for (int i=0; i<2; i++){
            SpcySqsxHyzt hy = new SpcySqsxHyzt();

            hy.setId(GetUuIdUtils.ReplaceUuId());
            hy.setFsqsxid(sqsxid);
            if (i == 0) {
                hy.setFhyzt(SqsxHyConstant.HYLX_SCHY);
                hy.setFhylx(SqsxHyConstant.HYLX_SCHY);
            }else {
                hy.setFhyzt(SqsxHyConstant.HYLX_MCHY);
                hy.setFhylx(SqsxHyConstant.HYLX_MCHY);
            }

            if (sqsx != null) {
                if (StringUtils.isNotBlank(sqsx.getFjcdd())) {
                    hy.setFhydd(sqsx.getFjcdd());
                }
                /*if (sqsx.getFcykssj() != null){
                    hy.setFhysj(sqsx.getFcykssj());
                }*/
            }

            hy.setFstate(SqsxHyConstant.getHyState(1));
            hy.setCreateTime(new Date());
            hy.setUpdateTime(new Date());

            hyList.add(hy);
        }
        if (CollectionUtil.isNotEmpty(hyList)){
            spcySqsxHyztService.saveBatch(hyList);
        }
    }

    /**
     * 现场检查-给会议设置默认时间
     */
    public void setDefaultHysjBySqsxId(String sqsxid, boolean schy, boolean mchy){
        try {
            if (schy){
                LambdaUpdateWrapper<SpcySqsxHyzt> updateWrapper = new LambdaUpdateWrapper<>();
                updateWrapper.eq(SpcySqsxHyzt::getFsqsxid, sqsxid);
                updateWrapper.eq(SpcySqsxHyzt::getFhylx, SqsxHyConstant.HYLX_SCHY);
                updateWrapper.isNull(SpcySqsxHyzt::getFhysj);

                SpcySqsxHyzt updateBean = new SpcySqsxHyzt();
                updateBean.setFhysj(new Date());

                spcySqsxHyztService.update(updateBean, updateWrapper);
            }

            if (mchy){
                LambdaUpdateWrapper<SpcySqsxHyzt> updateWrapper = new LambdaUpdateWrapper<>();
                updateWrapper.eq(SpcySqsxHyzt::getFsqsxid, sqsxid);
                updateWrapper.eq(SpcySqsxHyzt::getFhylx, SqsxHyConstant.HYLX_MCHY);
                updateWrapper.isNull(SpcySqsxHyzt::getFhysj);

                SpcySqsxHyzt updateBean = new SpcySqsxHyzt();
                updateBean.setFhysj(new Date());

                spcySqsxHyztService.update(updateBean, updateWrapper);
            }
        }catch (Exception e){
            log.error("现场检查-给会议设置默认时间-错误：", e.getMessage());
        }


    }

    /**
     * 首次会议提交-会议登记提交
     */
    public Result sqsxHySubmit(String fhyid, String sqsxid, SpcySqsxHyzt hy){
//        List<SpcyJcyFybxdgrjl> xpList = jcyFybxdService.queryBxryjlBySqsxId(sqsxid);
        List<SpcySqsxHydjry> xpList = jcyFybxdService.queryHydjryBySqsxId(sqsxid);
        if (CollectionUtil.isEmpty(xpList)){
            return Result.error("请选择需要登记的人员！");
        }

        hy.setFstate(SqsxHyConstant.getHyState(2));
        hy.setFhysj(new Date());
        boolean flag = spcySqsxHyztService.updateById(hy);
        if (!flag){
            return Result.error("操作失败，请重新操作！");
        }

        List<SpcySqsxHymx> mxList = new ArrayList<>();
        SpcySqsxHymx newHymx = null;
        for (SpcySqsxHydjry xpjl : xpList){
            newHymx = new SpcySqsxHymx();
            newHymx.setId(GetUuIdUtils.ReplaceUuId());
            newHymx.setFhyid(fhyid);
            newHymx.setFuserid(xpjl.getFuserid());

            /** 人员类型-检查身份 */
            if (!(StringUtils.isBlank(xpjl.getFjcsf()) || xpjl.getFjcsf().equals("无"))){
                if (xpjl.getFjcsf().equals(SqsxHyConstant.getHymxRylx(2))){
                    // 观察员
                    newHymx.setFrylx(xpjl.getFjcsf());
                    newHymx.setFjcsf(xpjl.getFjcsf());

                }else {
                    // 检查员
                    newHymx.setFrylx(SqsxHyConstant.getHymxRylx(1));
                    newHymx.setFjcsf(xpjl.getFjcsf());

                }
            }

            newHymx.setFxm(xpjl.getRealname());
            newHymx.setFbm(newHymx.getFjcsf());

            /** 签名 */
            String fqmfj = "";
            if (StringUtils.isNotBlank(xpjl.getFuserid())) {
                fqmfj = spcyMyInfoService.genUserSignLink(xpjl.getFuserid());
            }
            newHymx.setFqmfj(fqmfj);

            newHymx.setFhyqdzt(SqsxHyConstant.FHYQDZT_WQD);
            newHymx.setCreateTime(new Date());
            newHymx.setCreateBy(GetCurrentUserUtils.getCurrentUserAccount());

            mxList.add(newHymx);
        }


        /** 企业负责人 */
        SpcySqsxHymx qyfzr = new SpcySqsxHymx();
        qyfzr.setId(GetUuIdUtils.ReplaceUuId());
        qyfzr.setFhyid(fhyid);

        qyfzr.setFrylx(SqsxHyConstant.getHymxRylx(3));
        qyfzr.setFbm(SqsxHyConstant.getHymxQyRyLx(1));

        qyfzr.setFhyqdzt(SqsxHyConstant.FHYQDZT_WQD);
        qyfzr.setCreateTime(new Date());
        qyfzr.setCreateBy(GetCurrentUserUtils.getCurrentUserAccount());

        mxList.add(qyfzr);
        spcySqsxHymxService.saveBatch(mxList);

        return Result.ok();
    }

    /**
     * 验证会议完成-是否存在相关人员没有签到
     */
    public Result verifySqsxHyWcInExistsNotQdry(String fhyid){

        List<SpcySqsxHymx> list = spcySqsxHymxService.list(new LambdaQueryWrapper<SpcySqsxHymx>()
                .eq(SpcySqsxHymx::getFhyid, fhyid));
        if (CollectionUtil.isEmpty(list)){
            return Result.error("没有签到人员！");
        }

        /** 检查员 */
        List<SpcySqsxHymx> jcyList = list.stream()
                .filter(f ->
                        StringUtils.isNotBlank(f.getFrylx())
                                && f.getFrylx().equals(SqsxHyConstant.getHymxRylx(1))
                                && f.getFhyqdrq() == null
                )
                .collect(Collectors.toList());
        if (CollectionUtil.isNotEmpty(jcyList)){
            return Result.error("存在相关检查员没有进行签到！");
        }

        /** 观察员 */
        List<SpcySqsxHymx> gcyList = list.stream()
                .filter(f ->
                        StringUtils.isNotBlank(f.getFrylx())
                                && f.getFrylx().equals(SqsxHyConstant.getHymxRylx(2))
                                && f.getFhyqdrq() == null
                )
                .collect(Collectors.toList());
        if (CollectionUtil.isNotEmpty(gcyList)){
            return Result.error("存在相关观察员没有进行签到！");

        }

        /** 企业负责人 */
        List<SpcySqsxHymx> qyfzrList = list.stream()
                .filter(f ->
                        StringUtils.isNotBlank(f.getFrylx())
                                && f.getFrylx().equals(SqsxHyConstant.getHymxRylx(3))
                                && StringUtils.isNotBlank(f.getFbm())
                                && f.getFbm().equals(SqsxHyConstant.getHymxQyRyLx(1))
                )
                .collect(Collectors.toList());
        if (CollectionUtil.isEmpty(qyfzrList)){
            return Result.error("存在相关企业关键人员(企业负责人)没有进行签到！");
        }

        return Result.ok();
    }

    /**
     *  生成申请事项会议-现场检查纪律带签字模板
     */
    public String genSqsxHyXcjcjlTemplate(String sqsxid){
        List<SpcySqsxHyzt> hyList = spcySqsxHyztService.list(new LambdaQueryWrapper<SpcySqsxHyzt>()
                .eq(SpcySqsxHyzt::getFsqsxid, sqsxid)
                .eq(SpcySqsxHyzt::getFhylx, SqsxHyConstant.HYLX_SCHY)
                .orderByAsc(SpcySqsxHyzt::getFhysj));

        Map schyMap = this.getHyqdPrintInfo(hyList, true);

        String destWordUrl = "";
        try {
            destWordUrl = initWjjlService.initXcjcjlByHyxx(sqsxid, schyMap);
        }catch (Exception e){
            log.error("生成申请事项会议-现场检查纪律带签字模板错误：{}", e.getMessage());
        }

        return destWordUrl;
    }

    /**
     * 会议完成-首次/末次会议-生成对应的签到记录表
     */
//    @Async(value = "asyncNormalTask")
    public void initHyQdjlTable(SpcySqsxHyzt hy, String sqsxid, int hylxFlag){
        Map schyMap = null;
        Map mchyMap = null;
        if (StringUtils.isBlank(hy.getFhylx()) || hy.getFhylx().equals(SqsxHyConstant.HYLX_SCHY)) {
            hylxFlag = 1;

            schyMap = this.getHyqdPrintInfo(CollectionUtil.newArrayList(hy));
        }else if (hy.getFhylx().equals(SqsxHyConstant.HYLX_MCHY)){
            hylxFlag = 2;

            mchyMap = this.getHyqdPrintInfo(CollectionUtil.newArrayList(hy));
        }

        Result result = initWjjlService.genXcjchyqdbHtmlConvertFile(sqsxid, schyMap, mchyMap, hylxFlag);
        if (!result.isSuccess()){
            log.error("会议完成-首次/末次会议-生成对应的签到记录表错误：", result.getMessage());;
        }
    }

    /**
     * 验证会议 企业负责人、质量负责人、质量管理负责人、质量受权人
     * */
    public HttpResult verifyHyQdjlQyGjry(String hyid){
        List<SpcySqsxHymx> qygjryList = spcySqsxHymxService.list(new LambdaQueryWrapper<SpcySqsxHymx>()
                .eq(SpcySqsxHymx::getFhyid, hyid)
                .eq(SpcySqsxHymx::getFrylx, SqsxHyConstant.getHymxRylx(3))
                .eq(SpcySqsxHymx::getFhyqdzt, SqsxHyConstant.FHYQDZT_YQD)
        );

        String errorMsg = "";

        int order = 1;
        List<SpcySqsxHymx> verify1 = qygjryList.stream()
                .filter(f -> StringUtils.isNotBlank(f.getFbm()) && f.getFbm().contains(SqsxHyConstant.getHymxQyRyLx(1)))
                .collect(Collectors.toList());
        if (CollectionUtil.isEmpty(verify1)){
            errorMsg += order + ". " + SqsxHyConstant.getHymxQyRyLx(1) + ":";
            order++;
        }

        List<SpcySqsxHymx> verify2 = qygjryList.stream()
                .filter(f -> StringUtils.isNotBlank(f.getFbm()) && f.getFbm().contains(SqsxHyConstant.getHymxQyRyLx(2)))
                .collect(Collectors.toList());
        if (CollectionUtil.isEmpty(verify2)){
            errorMsg += StringUtils.isBlank(errorMsg) ? "" : "\n";
            errorMsg += order + ". " + SqsxHyConstant.getHymxQyRyLx(2) + ":";
            order++;
        }

        List<SpcySqsxHymx> verify3 = qygjryList.stream()
                .filter(f -> StringUtils.isNotBlank(f.getFbm()) && f.getFbm().contains(SqsxHyConstant.getHymxQyRyLx(5)))
                .collect(Collectors.toList());
        if (CollectionUtil.isEmpty(verify3)){

            List<SpcySqsxHymx> verify31 = qygjryList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getFbm()) && f.getFbm().contains(SqsxHyConstant.getHymxQyRyLx(3)))
                    .collect(Collectors.toList());
            if (CollectionUtil.isEmpty(verify31)){
                errorMsg += StringUtils.isBlank(errorMsg) ? "" : "\n";
                errorMsg += order + ". " + SqsxHyConstant.getHymxQyRyLx(3) + ":";
                order++;
            }

            List<SpcySqsxHymx> verify32 = qygjryList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getFbm()) && f.getFbm().contains(SqsxHyConstant.getHymxQyRyLx(4)))
                    .collect(Collectors.toList());
            if (CollectionUtil.isEmpty(verify32)){
                errorMsg += StringUtils.isBlank(errorMsg) ? "" : "\n";
                errorMsg += order + ". " + SqsxHyConstant.getHymxQyRyLx(4) + ":";
                order++;
            }
        }

        if (StringUtils.isNotBlank(errorMsg)){
            return HttpResultVo.HttpResultGet(errorMsg);
        }

        return HttpResult.ok();
    }

    /**
     * 打包下载相关文件的模板-到本地
     */
    public String downRsWjmbToLocal(String wjmbId, String sqsxid, String type, SpcySqsxBasic sqsx, boolean isWithMbData){
        if (!isWithMbData) {
            return initWjjlService.downRsWjmbToLocal(wjmbId, sqsxid, type, sqsx);
        }else {
            return initWjjlService.downloadSqsxWjmbToLocal(wjmbId, sqsxid, type, sqsx);
        }
    }

    /** 构建会议签到打印信息 */
    public Map getHyqdPrintInfo(List<SpcySqsxHyzt> hyList){
        return this.getHyqdPrintInfo(hyList, false);
    }
    public Map getHyqdPrintInfo(List<SpcySqsxHyzt> hyList, boolean isQyfzr){
        Map hyMap = null;

        for (int i = 0; i < hyList.size(); i++) {
            hyMap = new HashMap();

            hyMap.put("hy", hyList.get(0));

            /** 检查员、观察员、企业 */
            List<SpcySqsxHymx> jcyList = new ArrayList<>();
            List<SpcySqsxHymx> gcyList = new ArrayList<>();
            List<SpcySqsxHymx> qyList = new ArrayList<>();

            // 会议签到明细
            List<SpcySqsxHymx> hymxList = spcySqsxHymxService.list(new LambdaQueryWrapper<SpcySqsxHymx>()
                    .eq(SpcySqsxHymx::getFhyid, hyList.get(0).getId())
                    .eq(SpcySqsxHymx::getFhyqdzt, SqsxHyConstant.FHYQDZT_YQD)
                    .orderByAsc(SpcySqsxHymx::getCreateTime));

            if (CollectionUtil.isNotEmpty(hymxList)){

                jcyList = hymxList.stream().filter( f-> StringUtils.isNotBlank(f.getFrylx()) && f.getFrylx()
                        .equals("检查员")).collect(Collectors.toList());

                gcyList = hymxList.stream().filter( f-> StringUtils.isNotBlank(f.getFrylx()) && f.getFrylx()
                        .equals("观察员")).collect(Collectors.toList());

                if (isQyfzr) {
                    qyList = hymxList.stream()
                            .filter(f ->
                                    StringUtils.isNotBlank(f.getFrylx())
                                    && f.getFrylx().equals(SqsxHyConstant.getHymxRylx(3))
                                    && StringUtils.isNotBlank(f.getFbm())
                                    && f.getFbm().equals(SqsxHyConstant.getHymxQyRyLx(1))
                            )
                            .collect(Collectors.toList());
                }else {
                    qyList = hymxList.stream().filter(f -> StringUtils.isNotBlank(f.getFrylx()) && f.getFrylx()
                            .contains("企业")).collect(Collectors.toList());
                }

            }

            hyMap.put("jcyList", jcyList); // 检查员
            hyMap.put("gcyList", gcyList); // 观察员
            hyMap.put("qyList", qyList); // 企业

        }

        return hyMap;
    }

    /** 获取首次会议-相关人员签名 */
    public HashMap<String, Object> getXcjcbgQmBySchy(String sqsxid){
        Map hyMap = new HashMap();

        List<SpcySqsxHymx> hymxList = spcySqsxHyztService.selectHymxByFsqsxid(sqsxid, SqsxHyConstant.HYLX_SCHY);

        /** 检查员、观察员、企业 */
        List<SpcySqsxHymx> jcyList = new ArrayList<>();
        List<SpcySqsxHymx> gcyList = new ArrayList<>();
        List<SpcySqsxHymx> qyList = new ArrayList<>();

        if (CollectionUtil.isNotEmpty(hymxList)){

            jcyList = hymxList.stream().filter( f-> StringUtils.isNotBlank(f.getFrylx()) && f.getFrylx()
                    .equals("检查员")).collect(Collectors.toList());

            gcyList = hymxList.stream().filter( f-> StringUtils.isNotBlank(f.getFrylx()) && f.getFrylx()
                    .equals("观察员")).collect(Collectors.toList());

            /** 企业负责人 */
            qyList = hymxList.stream()
                    .filter(f ->
                            StringUtils.isNotBlank(f.getFrylx())
                                    && f.getFrylx().equals(SqsxHyConstant.getHymxRylx(3))
                                    && StringUtils.isNotBlank(f.getFbm())
                                    && f.getFbm().equals(SqsxHyConstant.getHymxQyRyLx(1))
                    )
                    .collect(Collectors.toList());


        }

        hyMap.put("jcyList", jcyList); // 检查员
        hyMap.put("gcyList", gcyList); // 观察员
        hyMap.put("qyList", qyList); // 企业


        return initWjjlService.initXcjcbgByHqxx(sqsxid, hyMap);
    }
}
